from .common import *

class AlphaOnlyValidator(wx.Validator):
    def __init__(self, pyVar=None):
        wx.Validator.__init__(self)
        self.Bind(wx.EVT_CHAR, self.OnChar)

    def Clone(self):
        return AlphaOnlyValidator()

    def Validate(self, win):
        # val = win.GetValue()
        # for x in val:
        #     if x not in string.ascii_letters+"_":
        #         return False
        return True
    
    def TransferToWindow(self):
        return True

    def TransferFromWindow(self):
        return True

    def OnChar(self, event):
        try:
            key = event.GetKeyCode()
        except:
            return
        if key == wx.WXK_DELETE:
            event.Skip()
            return
        if chr(key) in string.ascii_letters+"_":
            event.Skip()
            return
        if not wx.Validator.IsSilent():
            wx.Bell()
        return
